<!DOCTYPE html>
<html>

<head>
    <title>JS Alert and Confirm</title>
    <style>
        .btn {
            font-size: 48px;
        }
    </style>
    <script>
        function showAlert() {
            alert("This is an alert!");
        }

        function showConfirm() {
            if (confirm("Are you sure?")) {
                alert("Confirmed!");
            } else {
                alert("Cancelled!");
            }
        }

        function openNewUrl(url) {
            jsbridge.openWebView(url)
        }

        function jsTitle() {
            return 'Test by leon';
        }

        function nativeCallTestMethod(param1, param2) {
            console.log("参数1:" + param1 + ", 参数2:" + param2);
            return "成功调用了 JS 方法"
        }

        function previewFile() {
            const fileInput = document.getElementById('fileInput');
            const previewDiv = document.getElementById('preview');
            const file = fileInput.files[0];

            if (file && file.type.startsWith('image/')) {
                const reader = new FileReader();
                reader.onload = function (e) {
                    previewDiv.innerHTML = `<img src="${e.target.result}" alt="Preview" style="max-width:100%;" />`;
                };
                reader.readAsDataURL(file);
            } else {
                previewDiv.innerHTML = 'Preview not available';
            }
        }
    </script>
</head>

<body>
    <h1>Test JS Alert and Confirm</h1>
    <div style="margin-left: 15px;">
        <button class="btn" onclick="showAlert()">Show Alert</button>
    </div>
    <div style="margin-left: 15px; margin-top: 15px;">
        <button class="btn" onclick="showConfirm()">Show Confirm</button>
    </div>
    <div style="margin-left: 15px; margin-top: 15px;">
        <button class="btn" onclick="openNewUrl('https://www.baidu.com/')">打开百度</button>
    </div>
    <div style="margin-left: 15px; margin-top: 15px;">
        <form>
            <input class="btn" type="file" id="fileInput" accept="image/*" onchange="previewFile()">
            <div id="preview"></div>
        </form>
    </div>
</body>

</html>